package com.chat.demo.userservice;

import com.chat.demo.auth.annotation.JwtAuth;
import com.chat.demo.userservice.DTO.FriendShip.FriendApplyDTO;
import com.chat.demo.userservice.DTO.FriendShip.FriendInfo;
import com.chat.demo.userservice.DTO.FriendShip.FriendsListDTO;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/friends")
public class Friend_Controller {

    @Autowired
    private Friend_Service friendService;

    // 发送好友请求
    @JwtAuth
    @PostMapping("/send")
    public void sendFriendRequest(@RequestParam Long senderId, @RequestParam Long receiverId) {
        friendService.sendFriendRequest(senderId, receiverId);
    }

    // 接受好友请求
    @JwtAuth
    @PostMapping("/accept")
    public void acceptFriendRequest(@RequestParam Long requestId) {
        friendService.acceptFriendRequest(requestId);
    }

    // 拒绝好友请求
    @JwtAuth
    @PostMapping("/reject")
    public void rejectFriendRequest(@RequestParam Long requestId) {
        friendService.rejectFriendRequest(requestId);
    }

    // 删除好友关系
    @JwtAuth
    @DeleteMapping("/remove-friend")
    public void removeFriendship(@RequestParam("myId") Long myId, @RequestParam("brokeId") Long brokeId) {
        friendService.removeFriendship(myId, brokeId);
    }

    @JwtAuth
    @GetMapping("/isFriends")
    public boolean areFriends(@RequestParam Long a, @RequestParam Long b) {
        return friendService.checkIfAreFriends(a, b);
    }

    @JwtAuth
    @GetMapping("/findFriends")
    public List<FriendInfo> getFriends(HttpServletRequest request) {
        return friendService.getActiveFriends(request);
    }

    @JwtAuth
    @GetMapping("/getFriend")
    public List<FriendsListDTO> getFriend(HttpServletRequest request) {
        return friendService.getFriends(request);
    }

    @JwtAuth
    @GetMapping("/getApply/{id}")
    public List<FriendApplyDTO> getApply(@PathVariable Integer id) {
        return friendService.getPendingRequestsByUserId(id);
    }

}